<!DOCTYPE html>
<head>
    <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="You can loop through files and generate a JSON file that developers can consume like a help API. Developers can pull in values from the JSON into interface e...">
<meta name="keywords" content="publishingsingle_sourcingcontent_types,  API, content API, UI text, inline help, context-sensitive help, popovers, tooltips">
<title>Help APIs and UI tooltips | 常见故障解决方案</title>
<link rel="stylesheet" href="css/syntax.css">


<link rel="stylesheet" type="text/css" href="css/font-awesome.min-4.5.0.css">
<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">-->
<link rel="stylesheet" href="css/modern-business.css">
<link rel="stylesheet" href="css/lavish-bootstrap.css">
<link rel="stylesheet" href="css/customstyles.css">
<link rel="stylesheet" href="css/theme-blue.css">


<script type="text/javascript" charset="utf8" src="js/jquery.js"></script>
<script src="js/jquery.cookie.min.js"></script>
<script src="js/jquery.navgoco.min.js"></script>


<script src="js/bootstrap.min.js"></script>
<script src="js/anchor.min.js"></script>
<script src="js/toc.js"></script>
<script src="js/customscripts.js"></script>

<link rel="shortcut icon" href="images/favicon.ico">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://cdn.bootcss.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<link rel="alternate" type="application/rss+xml" title="" href="feed.xml">

    <script>
        $(document).ready(function() {
            // Initialize navgoco with default options
            $("#mysidebar").navgoco({
                caretHtml: '',
                accordion: true,
                openClass: 'active', // open
                save: false, // leave false or nav highlighting doesn't work right
                cookie: {
                    name: 'navgoco',
                    expires: false,
                    path: '/'
                },
                slide: {
                    duration: 400,
                    easing: 'swing'
                }
            });

            $("#collapseAll").click(function(e) {
                e.preventDefault();
                $("#mysidebar").navgoco('toggle', false);
            });

            $("#expandAll").click(function(e) {
                e.preventDefault();
                $("#mysidebar").navgoco('toggle', true);
            });

        });

    </script>
    <script>
        $(function () {
            $('[data-toggle="tooltip"]').tooltip()
        })
    </script>

    

</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container topnavlinks">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="fa fa-home fa-lg navbar-brand" href="index.html">&nbsp;<span class="projectTitle"> 常见故障解决方案</span></a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                <!-- entries without drop-downs appear here -->
                
                
                
                <li><a href="index.html">重新搜索</a></li>
                
                
                
                <!-- entries with drop-downs appear here -->
                <!-- conditional logic to control which topnav appears for the audience defined in the configuration file.-->
                
                
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">其他文档入口<b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        
                        
                        <li><a href="index.html">常见故障解决方案</a></li>
                        
                        
                        
                        <li><a href="p1_sample1.html">常用语法</a></li>
                        
                        
                    </ul>
                </li>
                
                
                
			<li><a class="email" title="问题反馈" href="#" onclick="javascript:window.location='mailto:Merlin_Wu@apllogistics.com?subject=《常见故障解决方案》反馈&body=%0D____________________________________________________________________%0D问题页面：%09Help APIs and UI tooltips %0D问题地址：%09' + window.location.href;"><i class="fa fa-envelope-o"></i> 邮件反馈</a><li>

		
                <!--comment out this block if you want to hide search-->
                <li>
                    <!--start search-->
                    <!-- <div id="search-demo-container">
                        <input type="text" id="search-input" placeholder="search...">
                        <ul id="results-container"></ul>
                    </div>
                    <script src="js/jekyll-search.js" type="text/javascript"></script>
                    <script type="text/javascript">
                            SimpleJekyllSearch.init({
                                searchInput: document.getElementById('search-input'),
                                resultsContainer: document.getElementById('results-container'),
                                dataSource: 'search.json',
                                searchResultTemplate: '<li><a href="{url}" title="Help APIs and UI tooltips">{title}</a></li>',
                    noResultsText: 'No results found.',
                            limit: 10,
                            fuzzy: true,
                    })
                    </script> -->
                    <!--end search-->
                </li>
            </ul>
        </div>
        </div>
        <!-- /.container -->
</nav>

<!-- Page Content -->
<div class="container">
    <div class="col-lg-12">&nbsp;</div>
    <!-- Content Row -->
    <div class="row">
        <!-- Sidebar Column -->
        <div class="col-md-3">

          












<!--  -->


<ul id="mysidebar" class="nav">
    <li class="sidebarTitle">目录 </li>
    
    
    
        
    
    <li>
        <a href="#">常用操作</a>
        <ul>
            
            
            
            <li><a href="index.html">搜索</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_introduction.html">Introduction</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_supported_features.html">Supported features</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_about.html">About the theme author</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_support.html">Support</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Release Notes</a>
        <ul>
            
            
            
            <li><a href="mydoc_release_notes_60.html">6.0 Release notes</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_release_notes_50.html">5.0 Release notes</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Installation</a>
        <ul>
            
            
            
            <li><a href="mydoc_about_ruby_gems_etc.html">About Ruby, Gems, Bundler, etc.</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_install_jekyll_on_mac.html">Install Jekyll on Mac</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_install_jekyll_on_windows.html">Install Jekyll on Windows</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Authoring</a>
        <ul>
            
            
            
            <li><a href="mydoc_pages.html">Pages</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_posts.html">Posts</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_lists.html">Lists</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_conditional_logic.html">Conditional logic</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_content_reuse.html">Content reuse</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_collections.html">Collections</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_webstorm_text_editor.html">WebStorm editor tips</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_atom_text_editor.html">Atom editor tips</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Navigation</a>
        <ul>
            
            
            
            <li><a href="mydoc_sidebar_navigation.html">Sidebar navigation</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_yaml_tutorial.html">YAML tutorial in the context of Jekyll</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_tags.html">Tags</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_series.html">Series</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Formatting</a>
        <ul>
            
            
            
            <li><a href="mydoc_adding_tooltips.html">Tooltips</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_alerts.html">Alerts</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_icons.html">Icons</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_images.html">Images</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_code_samples.html">Code samples</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_labels.html">Labels</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_hyperlinks.html">Links</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_navtabs.html">Navtabs</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_tables.html">Tables</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_syntax_highlighting.html">Syntax highlighting</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_workflow_maps.html">Workflow maps</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Handling reviews</a>
        <ul>
            
            
            
            <li><a href="mydoc_commenting_on_files.html">Commenting on files</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Publishing</a>
        <ul>
            
            
            
            <li><a href="mydoc_build_arguments.html">Build arguments</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_themes.html">Themes</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_generating_pdfs.html">Generating PDFs</a></li>
            
            
            
            
            
            
            <li class="active"><a href="mydoc_help_api.html">Help APIs and UI tooltips</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_search_configuration.html">Search configuration</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_iterm_profiles.html">iTerm profiles</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_push_build_to_server.html">Pushing builds to server</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_no_password_prompts_scp.html">Getting around the password prompts in SCP</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_publishing_github_pages.html">Publishing on Github Pages</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Special layouts</a>
        <ul>
            
            
            
            <li><a href="mydoc_kb_layout.html">Knowledge-base layout</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_glossary.html">Glossary layout</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_faq_layout.html">FAQ layout</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_scroll.html">Scroll layout</a></li>
            
            
            
            
            
            
            <li><a href="mydoc_shuffle.html">Shuffle layout</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Troubleshooting</a>
        <ul>
            
            
            
            <li><a href="mydoc_troubleshooting.html">Troubleshooting</a></li>
            
            
            
            
        </ul>
        
        
    
    <li>
        <a href="#">Tag archives</a>
        <ul>
            
            
            
            <li><a href="mydoc_tag_archives_overview.html">Tag archives overview</a></li>
            
            
            
            <li class="subfolders">
                <a href="#">Tag archive pages</a>
                <ul>
                    
                    
                    
                    <li><a href="tag_formatting.html">Formatting pages</a></li>
                    
                    
                    
                    
                    
                    <li><a href="tag_navigation.html">Navigation pages</a></li>
                    
                    
                    
                    
                    
                    <li><a href="tag_content_types.html">Content types pages</a></li>
                    
                    
                    
                    
                    
                    <li><a href="tag_publishing.html">Publishing pages</a></li>
                    
                    
                    
                    
                    
                    <li><a href="tag_special_layouts.html">Special layout pages</a></li>
                    
                    
                    
                    
                    
                    <li><a href="tag_collaboration.html">Collaboration pages</a></li>
                    
                    
                    
                    
                    
                    <li><a href="tag_troubleshooting.html">Troubleshooting pages</a></li>
                    
                    
                    
                </ul>
            </li>
            
            
            
            
        </ul>
        
        
        
        <!-- if you aren't using the accordion, uncomment this block:
           <p class="external">
               <a href="#" id="collapseAll">Collapse All</a> | <a href="#" id="expandAll">Expand All</a>
           </p>
           -->
    </li>
</ul>
</div>

<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above. Otherwise, if placed inside customscripts.js, the script runs before the sidebar code runs and the class never gets inserted.-->
<script>$("li.active").parents('li').toggleClass("active");</script>

    <!-- Content Column -->
    <div class="col-md-9">
        <div class="post-header">
   <h1 class="post-title-main">Help APIs and UI tooltips</h1>
</div>



<div class="post-content">

   
    <div class="summary">You can loop through files and generate a JSON file that developers can consume like a help API. Developers can pull in values from the JSON into interface elements, styling them as popovers for user interface text, for example. The beauty of this method is that the UI text remains in the help system (or at least in a single JSON file delivered to the dev team) and isn't hard-coded into the UI.</div>
   

    
    
<!-- this handles the automatic toc. use ## for subheads to auto-generate the on-page minitoc. if you use html tags, you must supply an ID for the heading element in order for it to appear in the minitoc. -->
<script>
$( document ).ready(function() {
  // Handler for .ready() called.

$('#toc').toc({ minimumHeaders: 0, listType: 'ul', showSpeed: 0, headers: 'h2,h3,h4' });

/* this offset helps account for the space taken up by the floating toolbar. */
$('#toc').on('click', 'a', function() {
  var target = $(this.getAttribute('href'))
    , scroll_target = target.offset().top

  $(window).scrollTop(scroll_target - 10);
  return false
})
  
});
</script>

<div id="toc"></div>

    

    

    

    

  <h2 id="full-code-demo-of-content-api">Full code demo of content API</h2>

<p>You can create a help API that developers can use to pull in content.</p>

<p>For the full code demo, see the notes in the <a href="tooltips.html">Tooltips file</a>.</p>

<p>In this demo, the popovers pull in and display content from the information in a <a target="_blank" href="tooltips.json">tooltips.json</a> file located in the same directory.</p>

<p>Instead of placing the JSON source in the same directory, you could also host the JSON file on another site.</p>

<p>Additionally, instead of tooltip popovers, you could also print content directly to the page. Basically, whatever you can stuff into a JSON file, developers can integrate it onto a page.</p>

<h2 id="diagram-overview">Diagram overview</h2>

<p>Here’s a diagram showing the basic idea of the help API:</p>

<p><img src="images/helpapi.svg" style="width: 650px;" /></p>

<p>Is this really an API? Well, sort of. The help content is pushed out into a JSON file that other websites and applications can easily consume. The endpoints don’t deliver different data based on parameters added to a URL. But the overall concept is similar to an API: you have a client requesting resources from a server.</p>

<p>Note that in this scenario, the help is openly accessible on the web. If you have a private system, it’s more complicated.</p>

<p>To deliver help this way using Jekyll, follow the steps in each of the sections below.</p>

<h2 id="create-a-collection-for-the-help-content">1. Create a “collection” for the help content</h2>

<p>A collection is another content type that extends Jekyll beyond the use of pages and posts. Call the collection “tooltips.”</p>

<p>Add the following information to your configuration file to declare your collection:</p>

<div class="language-liquid highlighter-rouge"><pre class="highlight"><code>collections:
  tooltips:
    output: false
</code></pre>
</div>

<p>In your Jekyll project’s root directory, create a new folder called “_tooltips” and put every page that you want to be part of that tooltips collection inside that folder.</p>

<p>In Jekyll, folders that begin with an underscore (“_”) aren’t included in the output. However, in the collection information that you add to your configuration file, if you change <code class="highlighter-rouge">output</code> to <code class="highlighter-rouge">true</code>, the tooltips folder will appear in the output, and each page inside tooltips will be generated. You most likely don’t want this for tooltips (you just want the JSON file), so make the <code class="highlighter-rouge">output</code> setting <code class="highlighter-rouge">false</code>.</p>

<h2 id="create-tooltip-definitions-in-a-yaml-file">2. Create tooltip definitions in a YAML file</h2>

<p>Inside the _data folder, create a YAML file called something like definitions.yml. Add the definitions for each of your tooltips here like this:</p>

<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">basketball</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Basketball</span><span class="nv"> </span><span class="s">is</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">sport</span><span class="nv"> </span><span class="s">involving</span><span class="nv"> </span><span class="s">two</span><span class="nv"> </span><span class="s">teams</span><span class="nv"> </span><span class="s">of</span><span class="nv"> </span><span class="s">five</span><span class="nv"> </span><span class="s">players</span><span class="nv"> </span><span class="s">each</span><span class="nv"> </span><span class="s">competing</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">put</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">ball</span><span class="nv"> </span><span class="s">through</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">small</span><span class="nv"> </span><span class="s">circular</span><span class="nv"> </span><span class="s">rim</span><span class="nv"> </span><span class="s">10</span><span class="nv"> </span><span class="s">feet</span><span class="nv"> </span><span class="s">above</span><span class="nv"> </span><span class="s">the</span><span class="nv"> </span><span class="s">ground.</span><span class="nv"> </span><span class="s">Basketball</span><span class="nv"> </span><span class="s">requires</span><span class="nv"> </span><span class="s">players</span><span class="nv"> </span><span class="s">to</span><span class="nv"> </span><span class="s">be</span><span class="nv"> </span><span class="s">in</span><span class="nv"> </span><span class="s">top</span><span class="nv"> </span><span class="s">physical</span><span class="nv"> </span><span class="s">condition,</span><span class="nv"> </span><span class="s">since</span><span class="nv"> </span><span class="s">they</span><span class="nv"> </span><span class="s">spend</span><span class="nv"> </span><span class="s">most</span><span class="nv"> </span><span class="s">of</span><span class="nv"> </span><span class="s">the</span><span class="nv"> </span><span class="s">game</span><span class="nv"> </span><span class="s">running</span><span class="nv"> </span><span class="s">back</span><span class="nv"> </span><span class="s">and</span><span class="nv"> </span><span class="s">forth</span><span class="nv"> </span><span class="s">along</span><span class="nv"> </span><span class="s">a</span><span class="nv"> </span><span class="s">94-foot-long</span><span class="nv"> </span><span class="s">floor."</span>
</code></pre>
</div>

<p>The definition of basketball is stored this data file so that you can re-use it in other parts of the help as well. You’ll likely want the definition to appear not only in the tooltip in the UI, but also in the regular documentation as well.</p>

<h2 id="create-pages-in-your-collection">3. Create pages in your collection</h2>

<p>Create pages inside your new tooltips collection (that is, inside the _tooltips folder). Each page needs to have a unique <code class="highlighter-rouge">id</code> in the frontmatter as well as a <code class="highlighter-rouge">product</code>. Then reference the definition you created in the definitions.yml file.</p>

<p>Here’s an example:</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="err">```</span><span class="s">liquid</span>
<span class="nn">---</span>
<span class="s">id</span><span class="pi">:</span> <span class="s">basketball</span>
<span class="s">product</span><span class="pi">:</span> <span class="s">mydoc</span>
<span class="nn">---</span>

<span class="pi">{{</span><span class="nv">site.data.definitions.basketball</span><span class="pi">}}</span>
<span class="err">```</span></code></pre></figure>

<p>You need to create a separate page for each tooltip you want to deliver.</p>

<p>The product attribute is required in the frontmatter to distinguish the tooltips produced here from the tooltips for other products in the same _tooltips folder. When creating the JSON file, Jekyll will iterate through all the pages inside _tooltips, regardless of any subfolders included here.</p>

<h2 id="create-a-json-file-that-loops-through-your-collection-pages">4. Create a JSON file that loops through your collection pages</h2>

<p>Now it’s time to create a JSON file with Liquid code that iterates through our tooltip collection and grabs the information from each tooltip file.</p>

<p>Inside your project’s pages directory (e.g., mydoc), add a file called “tooltips.json.” (You can use whatever name you want.) Add the following to your JSON file:</p>

<div class="language-liquid highlighter-rouge"><pre class="highlight"><code>---
layout: none
search: exclude
---
{
"entries":
[
<span class="p">{%</span><span class="w"> </span><span class="nt">for</span><span class="w"> </span>page<span class="w"> </span>in<span class="w"> </span>site.tooltips<span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="kr">if</span><span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">product</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"mydoc"</span><span class="w"> </span><span class="p">%}</span>
{
"id"    : "<span class="p">{{</span><span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">id</span><span class="w"> </span><span class="p">}}</span>",
"body": "<span class="p">{{</span><span class="w"> </span><span class="nv">page</span><span class="p">.</span><span class="nv">content</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">strip_newlines</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">replace</span><span class="p">:</span><span class="w"> </span><span class="s1">'\'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\\\'</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">replace</span><span class="p">:</span><span class="w"> </span><span class="s1">'"'</span><span class="p">,</span><span class="w"> </span><span class="s1">'\\"'</span><span class="w"> </span><span class="p">}}</span>"
} <span class="p">{%</span><span class="w"> </span><span class="kr">unless</span><span class="w"> </span><span class="nv">forloop</span><span class="p">.</span><span class="nv">last</span><span class="w"> </span><span class="p">%}</span>,<span class="p">{%</span><span class="w"> </span><span class="kr">endunless</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="kr">endif</span><span class="w"> </span><span class="p">%}</span>
<span class="p">{%</span><span class="w"> </span><span class="nt">endfor</span><span class="w"> </span><span class="p">%}</span>
]
}
</code></pre>
</div>

<p>Change “mydoc” to the product name you used in each of the tooltip files. The template here will only include content in the JSON file if it meets the <code class="highlighter-rouge">product</code> attribute requirements. We need this <code class="highlighter-rouge">if</code> statement to prevent tooltips from other products from being included in the JSON file.</p>

<p>This code will loop through all pages in the tooltips collection and insert the <code class="highlighter-rouge">id</code> and <code class="highlighter-rouge">body</code> into key-value pairs for the JSON code. Here’s an example of what that looks like after it’s processed by Jekyll in the site build:</p>

<div class="highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nt">"entries"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
    </span><span class="p">{</span><span class="w">
      </span><span class="nt">"id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"baseball"</span><span class="p">,</span><span class="w">
      </span><span class="nt">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Baseball is considered America's pasttime sport, though that may be more of a historical term than a current one. There's a lot more excitement about football than baseball. A baseball game is somewhat of a snooze to watch, for the most part."</span><span class="w">
    </span><span class="p">},</span><span class="w">
    </span><span class="p">{</span><span class="w">
      </span><span class="nt">"id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"basketball"</span><span class="p">,</span><span class="w">
      </span><span class="nt">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Basketball is a sport involving two teams of five players each competing to put a ball through a small circular rim 10 feet above the ground. Basketball requires players to be in top physical condition, since they spend most of the game running back and forth along a 94-foot-long floor."</span><span class="w">
    </span><span class="p">},</span><span class="w">
    </span><span class="p">{</span><span class="w">
      </span><span class="nt">"id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"football"</span><span class="p">,</span><span class="w">
      </span><span class="nt">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"No doubt the most fun sport to watch, football also manages to accrue the most injuries with the players. From concussions to blown knees, football players have short sport lives."</span><span class="w">
    </span><span class="p">},</span><span class="w">
    </span><span class="p">{</span><span class="w">
      </span><span class="nt">"id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"soccer"</span><span class="p">,</span><span class="w">
      </span><span class="nt">"body"</span><span class="p">:</span><span class="w"> </span><span class="s2">"If there's one sport that dominates the world landscape, it's soccer. However, US soccer fans are few and far between. Apart from the popularity of soccer during the World Cup, most people don't even know the name of the professional soccer organization in their area."</span><span class="w">
    </span><span class="p">}</span><span class="w">
  </span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre>
</div>

<p>You can also view the same JSON file here: <a target="_blank" href="tooltips.json">tooltips.json</a>.</p>

<p>You can add different fields depending on how you want the JSON to be structured. Here we just have to fields: <code class="highlighter-rouge">id</code> and <code class="highlighter-rouge">body</code>. And the JSON is looking just in the tooltips collection that we created.</p>

<div class="alert alert-success" role="alert"><i class="fa fa-check-square-o"></i> <b>Tip:</b> Check out <a href="https://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml">Google’s style guide</a> for JSON. These best practices can help you keep your JSON file valid.</div>

<p>Note that you can create different JSON files that specialize in different content. For example, suppose you have some getting started information. You could put that into a different JSON file. Using the same structure, you might add an <code class="highlighter-rouge">if</code> tag that checks whether the page has frontmatter that says <code class="highlighter-rouge">type: getting_started</code> or something. Or you could put the content into separate collection entirely (different from tooltips).</p>

<p>By chunking up your JSON files, you can provide a quicker lookup. (I’m not sure how big the JSON file can be before you experience any latency with the jQuery lookup.)</p>

<h2 id="build-your-site-and-look-for-the-json-file">5. Build your site and look for the JSON file</h2>

<p>When you build your site, Jekyll will iterate through every page in your _tooltips folder and put the page id and body into this format. In the output, look for the JSON file in the tooltips.json file. You’ll see that Jekyll has populated it with content. This is because of the triple hyphen lines in the JSON file — this instructs Jekyll to process the file.</p>

<h2 id="allow-cors-access-to-your-help-if-stored-on-a-remote-server">6. Allow CORS access to your help if stored on a remote server</h2>

<p>You can simply deliver the JSON file to devs to add to the project. But if you have the option, it’s best to keep the JSON file stored in your own help system. Assuming you have the ability to update your content on the fly, this will give you completely control over the tooltips without being tied to a specific release window.</p>

<p>When people make calls to your site <em>from other domains</em>, you must allow them access to get the content. To do this, you have to enable something called CORS (cross origin resource sharing) within the server where your help resides.</p>

<p>In other words, people are going to be executing calls to reach into your site and grab your content. Just like the door on your house, you have to unlock it so people can get in. Enabling CORS is unlocking it.</p>

<p>How you enable CORS depends on the type of server.</p>

<p>If your server setup allows htaccess files to override general server permissions, create an .htaccess file and add the following:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>Header set Access-Control-Allow-Origin "*"
</code></pre>
</div>

<p>Store this in the same directory as your project. This is what I’ve done in a directory on my web host (bluehost.com). Inside http://idratherassets.com/wp-content/apidemos/, I uploaded a file called “.htaccess” with the preceding code.</p>

<p>After I uploaded it, I renamed it to .htaccess, right-clicked the file and set the permissions to 774.</p>

<p>To test whether your server permissions are set correctly, open a terminal and run the following curl command pointing to your tooltips.json file:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>curl -I http://idratherassets.com/wp-content/apidemos/tooltips.json
</code></pre>
</div>

<p>The <code class="highlighter-rouge">-I</code> command tells cURL to return the request header only.</p>

<p>If the server permissions are set correctly, you should see the following line somewhere in the response:</p>

<div class="language-xml highlighter-rouge"><pre class="highlight"><code>Access-Control-Allow-Origin: *
</code></pre>
</div>

<p>If you don’t see this response, CORS isn’t allowed for the file.</p>

<p>If you have an AWS S3 bucket, you can supposedly add a CORS configuration to the bucket permissions. Log into AWS S3 and click your bucket. On the right, in the Permissions section, click <strong>Add CORS Configuration</strong>. In that space, add the following policy:</p>

<div class="language-xml highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;CORSConfiguration&gt;</span>
 <span class="nt">&lt;CORSRule&gt;</span>
   <span class="nt">&lt;AllowedOrigin&gt;</span>*<span class="nt">&lt;/AllowedOrigin&gt;</span>
   <span class="nt">&lt;AllowedMethod&gt;</span>GET<span class="nt">&lt;/AllowedMethod&gt;</span>
 <span class="nt">&lt;/CORSRule&gt;</span>
<span class="nt">&lt;/CORSConfiguration&gt;</span>
</code></pre>
</div>

<p>(Although this should work, in my experiment it doesn’t. And I’m not sure why…)</p>

<p>In other server setups, you may need to edit one of your Apache configuration files. See <a href="http://enable-cors.org/server.html">Enable CORS</a> or search online for ways to allow CORS for your server.</p>

<p>If you don’t have CORS enabled, users will see a CORS error/warning message in the console of the page making the request.</p>

<div class="alert alert-success" role="alert"><i class="fa fa-check-square-o"></i> <b>Tip:</b> If enabling CORS is problematic, you could always just send developers the tooltips.json file and ask them to place it on their own server.</div>

<h2 id="explain-how-developers-can-access-the-help">7. Explain how developers can access the help</h2>

<p>Developers can access the help using the <code class="highlighter-rouge">.get</code> method from jQuery, among other methods. Here’s an example of how to get a page with the ID of <code class="highlighter-rouge">basketball</code>:</p>

<div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text/javascript"</span><span class="o">&gt;</span>
<span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>

<span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="s2">"mydoc_tooltips_source.json"</span><span class="p">;</span>


<span class="nx">$</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span> <span class="nx">url</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span> <span class="nx">data</span> <span class="p">)</span> <span class="p">{</span>

        <span class="nx">$</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">entries</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">page</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">if</span> <span class="p">(</span><span class="nx">page</span><span class="p">.</span><span class="nx">id</span> <span class="o">==</span> <span class="s2">"basketball"</span><span class="p">)</span> <span class="p">{</span>
            <span class="nx">$</span><span class="p">(</span> <span class="s2">"#basketball"</span> <span class="p">).</span><span class="nx">attr</span><span class="p">(</span> <span class="s2">"data-content"</span><span class="p">,</span> <span class="nx">page</span><span class="p">.</span><span class="nx">body</span> <span class="p">);</span>
            <span class="p">}</span>

        <span class="p">});</span>
    <span class="p">});</span>

<span class="p">});</span>
<span class="o">&lt;</span><span class="sr">/script</span><span class="err">&gt;
</span></code></pre>
</div>

<p>View the <a target="_blank" href="tooltips.html" class="noCrossRef">tooltip demo</a> for a demonstration.</p>

<p>The <code class="highlighter-rouge">url</code> in the demo is relative, but you could equally point it to an absolute path on a remote host assuming CORS is enabled on the host.</p>

<p>The <code class="highlighter-rouge">each</code> method looks through all the JSON content to find the item whose <code class="highlighter-rouge">page.id</code> is equal to <code class="highlighter-rouge">basketball</code>. It then looks for an element on the page named <code class="highlighter-rouge">#basketball</code> and adds a <code class="highlighter-rouge">data-content</code> attribute to that element.</p>

<div class="alert alert-danger" role="alert"><i class="fa fa-exclamation-circle"></i> <b>Warning:</b> Make sure your JSON file is valid. Otherwise, this method won’t work. I use the <a href="https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en">JSON Formatter extension for Chrome</a>. When I go to the tooltips.json page in my browser, the JSON content — if valid — is nicely formatted (and includes some color coding). If the file isn’t valid, it’s not formatted and there isn’t any color. You can also check the JSON formatting using <a href="http://jsonformatter.curiousconcept.com/">JSON Formatter and Validator</a>. If your JSON file isn’t valid, identify the problem area using the validator and troubleshoot the file causing issues. It’s usually due to some code that isn’t escaping correctly.</div>

<p>Why <code class="highlighter-rouge">data-content</code>? Well, in this case, I’m using <a href="http://getbootstrap.com/javascript/#popovers">Bootstrap popovers</a> to display the tooltip content. The <code class="highlighter-rouge">data-content</code> attribute is how Bootstrap injects popovers.</p>

<p>Here’s the section on the page where the popover is inserted:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>&lt;p&gt;Basketball &lt;span class="glyphicon glyphicon-info-sign" id="basketball" data-toggle="popover"&gt;&lt;/span&gt;&lt;/p&gt;
</code></pre>
</div>

<p>Notice that I just have <code class="highlighter-rouge">id="basketball"</code> added to this popover element. Developers merely need to add a unique ID to each tooltip they want to pull in the help content. Either you tell developers the unique ID they should add, or ask them what IDs they added (or just tell them to use an ID that matches the field’s name).</p>

<p>In order to use jQuery and Bootstrap, you’ll need to add the appropriate references in the head tags of your page:</p>

<div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="o">&lt;</span><span class="nx">link</span> <span class="nx">rel</span><span class="o">=</span><span class="s2">"stylesheet"</span> <span class="nx">href</span><span class="o">=</span><span class="s2">"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"</span><span class="o">&gt;</span>
<span class="o">&lt;</span><span class="nx">script</span> <span class="nx">src</span><span class="o">=</span><span class="s2">"https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"</span><span class="o">&gt;&lt;</span><span class="sr">/script</span><span class="err">&gt;
</span><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">src</span><span class="o">=</span><span class="s2">"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"</span><span class="o">&gt;&lt;</span><span class="sr">/script</span><span class="err">&gt;
</span>
<span class="o">&lt;</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text/javascript"</span><span class="o">&gt;</span>
<span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
    <span class="nx">$</span><span class="p">(</span><span class="s1">'[data-toggle="popover"]'</span><span class="p">).</span><span class="nx">popover</span><span class="p">({</span>
        <span class="na">placement</span> <span class="p">:</span> <span class="s1">'right'</span><span class="p">,</span>
        <span class="na">trigger</span><span class="p">:</span> <span class="s1">'hover'</span><span class="p">,</span>
        <span class="na">html</span><span class="p">:</span> <span class="kc">true</span>
    <span class="p">});</span>
</code></pre>
</div>

<p>Again, see the <a class="noCrossRef" href="/tooltips">Tooltip Demo</a> for a demo of the full code.</p>

<p>Note that even though you reference a Bootstrap JS script, Bootstrap’s popovers require you to initialize them using the above code as well — they aren’t turned on by default.</p>

<p>View the source code of the <a target="_blank" href="tooltips.html" class="noCrossRef">tooltip demo</a> for the full comments.</p>

<h2 id="create-easy-links-to-embed-the-help-in-your-help-site">8. Create easy links to embed the help in your help site</h2>

<p>You might also want to insert the same content into different parts of your help site. For example, if you have tooltips providing definitions for fields, you’ll probably want to create a page in your help that lists those same definitions.</p>

<p>You could use the same method developers use to pull help content into their applications. But it will probably be easier to simply use Jekyll’s tags for doing it.</p>

<p>Here’s how you would reuse the content:</p>

<div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;h2&gt;</span>Reuse Demo<span class="nt">&lt;/h2&gt;</span>


<span class="nt">&lt;table&gt;</span>
<span class="nt">&lt;thead&gt;</span>
<span class="nt">&lt;tr&gt;</span>
<span class="nt">&lt;th&gt;</span>Sport<span class="nt">&lt;/th&gt;</span>
<span class="nt">&lt;th&gt;</span>Comments<span class="nt">&lt;/th&gt;</span>
<span class="nt">&lt;/tr&gt;</span>
<span class="nt">&lt;/thead&gt;</span>
<span class="nt">&lt;tbody&gt;</span>

<span class="nt">&lt;tr&gt;</span>
<span class="nt">&lt;td&gt;</span>Basketball<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;td&gt;</span>{{site.data.definitions.basketball}}<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>

<span class="nt">&lt;tr&gt;</span>
<span class="nt">&lt;td&gt;</span>Baseball<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;td&gt;</span>{{site.data.definitions.baseball}}<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>

<span class="nt">&lt;tr&gt;</span>
<span class="nt">&lt;td&gt;</span>Football<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;td&gt;</span>{{site.data.definitions.football}}<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>

<span class="nt">&lt;tr&gt;</span>
<span class="nt">&lt;td&gt;</span>Soccer<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;td&gt;</span>{{site.data.definitions.soccer}}<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;</span>
<span class="nt">&lt;/tbody&gt;</span>
<span class="nt">&lt;/table&gt;</span>
</code></pre>
</div>

<p>And here’s the code:</p>

<h2>Reuse Demo</h2>

<table>
<thead>
<tr>
<th>Sport</th>
<th>Comments</th>
</tr>
</thead>
<tbody>

<tr>
<td>Basketball</td>
<td>Basketball is a sport involving two teams of five players each competing to put a ball through a small circular rim 10 feet above the ground. Basketball requires players to be in top physical condition, since they spend most of the game running back and forth along a 94-foot-long floor.</td>
</tr>

<tr>
<td>Baseball</td>
<td>Baseball is considered America's pasttime sport, though that may be more of a historical term than a current one. There's a lot more excitement about football than baseball. A baseball game is somewhat of a snooze to watch, for the most part.</td>
</tr>

<tr>
<td>Football</td>
<td>No doubt the most fun sport to watch, football also manages to accrue the most injuries with the players. From concussions to blown knees, football players have short sport lives.</td>
</tr>

<tr>
<td>Soccer</td>
<td>If there's one sport that dominates the world landscape, it's soccer. However, US soccer fans are few and far between. Apart from the popularity of soccer during the World Cup, most people don't even know the name of the professional soccer organization in their area.</td>
</tr>
</tbody>
</table>

<p>Now you have both documentation and UI tooltips generated from the same definitions file.</p>



    <div class="tags">
        
        <b>Tags: </b>
        
        
        
        <a href="tag_publishing.html" class="btn btn-default navbar-btn cursorNorm" role="button">publishing</a>
        
        
        
        <a href="tag_single_sourcing.html" class="btn btn-default navbar-btn cursorNorm" role="button">single_sourcing</a>
        
        
        
        <a href="tag_content_types.html" class="btn btn-default navbar-btn cursorNorm" role="button">content_types</a>
        
        
        
    </div>

    

</div>

<hr class="shaded"/>

<footer>
            <div class="row">
                <div class="col-lg-12 footer">
               &copy;2016 . All rights reserved. <br />
<span>Page last updated:</span> July 3, 2016<br/> Site last generated: Oct 8, 2016 <br />
<!-- <p><img src="images/company_logo.png" alt="Company logo"/></p> -->
                </div>
            </div>
</footer>


    </div>
    <!-- /.row -->
</div>
<!-- /.container -->
    </div>

</body>

</html>
